import { formatDataToUrl } from './common';

export * from './common';

export function storage(key: string, value?: any) {
  if (arguments.length === 1) {
    try {
      return wx.getStorageSync(key)
    } catch (e) {
      // Do something when catch error
      return '';
    }
  } else {
    try {
      wx.setStorageSync(key, value);
    } catch (e) {
      // Do something when catch error
    }
  }
}

// 获取query参数
export const getUrl = () => {
  var pages = getCurrentPages();    //获取加载的页面
  var currentPage = pages[pages.length - 1]    //获取当前页面的对象
  currentPage = currentPage ? currentPage : { route: "", options: {} };
  // return currentPage;
  return formatDataToUrl(currentPage.route, currentPage.options)
} 